<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('请假记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" id="chiefId" name="chiefId" th:value="${chiefId}">
                    <input type="hidden" id="manageId" name="manageId" th:value="${manageId}">
                    <input type="hidden" id="humanId" name="humanId" th:value="${humanId}">
                    <input type="hidden" id="leaderId" name="leaderId" th:value="${leaderId}">
                    <input type="hidden" id="adminId" name="adminId" th:value="${adminId}">
                    <input type="hidden" id="partyId" name="partyId" th:value="${partyId}">
                    <input type="hidden" id="verifyType" name="verifyType" th:value="${verifyType}">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>请假科室：</label>
                                <input type="text" name="deptName"/>
                            </li>
                            <li>
                                <label>请假人员：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>休假类型：</label>
                                <select name="leaveType" th:with="type=${@dict.getType('record_leave_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning single disabled" onclick="verify()" shiro:hasPermission="record:verify:save">
                    <i class="fa fa-print"></i> 审批
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var leaveTypeDatas = [[${@dict.getType('record_leave_type')}]];
        var workDutyDatas = [[${@dict.getType('basic_work_duty')}]];
        var prefix = ctx + "record/leave/verify";

        var verifyType = [[${verifyType}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                modalName: "待审核记录",
                sortName: "createTime",
                sortOrder: "desc",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'leaveId',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'userType',
                    title: '人员类型',
                    formatter: function(value, row, index) {
                        if(value == '01') {
                            return "普通职工";
                        }else {
                            return "中层及以上";
                        }
                    }
                },
                {
                    field: 'userName',
                    title: '请假人'
                },
                {
                    field: 'agentUser',
                    title: '代理人'
                },
                {
                    field: 'leaveType',
                    title: '休假类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(leaveTypeDatas, value);
                    }
                },
                {
                    field: 'workDuty',
                    title: '编制情况',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(workDutyDatas, value);
                    }
                },
                {
                    field: 'leaveContent',
                    title: '请假事由'
                },
                {
                    field: 'startTime',
                    title: '开始时间'
                },
                {
                    field: 'endTime',
                    title: '结束时间'
                },
                {
                    field: 'days',
                    title: '天数'
                },
                {
                    title: '审批状态',
                    formatter: function(value, row, index) {
                        if(verifyType == 'chief') {
                            if(row.chiefFlag == '0') {
                                return '<span class="label label-default">未审批</span>';
                            }else if(row.chiefFlag == '1') {
                                return '<span class="label label-success">审批同意</span>';
                            }else {
                                return '<span class="label label-warning">审批不同意</span>';
                            }
                        } else if(verifyType == 'manage') {
                            if(row.manageFlag == '0') {
                                return '<span class="label label-default">未审批</span>';
                            }else if(row.manageFlag == '1') {
                                return '<span class="label label-success">审批同意</span>';
                            }else {
                                return '<span class="label label-warning">审批不同意</span>';
                            }
                        } else if(verifyType == 'human') {
                            if(row.humanFlag == '0') {
                                return '<span class="label label-default">未审批</span>';
                            }else if(row.humanFlag == '1') {
                                return '<span class="label label-success">审批同意</span>';
                            }else {
                                return '<span class="label label-warning">审批不同意</span>';
                            }
                        } else if(verifyType == 'leader') {
                            if(row.leaderFlag == '0') {
                                return '<span class="label label-default">未审批</span>';
                            }else if(row.leaderFlag == '1') {
                                return '<span class="label label-success">审批同意</span>';
                            }else {
                                return '<span class="label label-warning">审批不同意</span>';
                            }
                        } else if(verifyType == 'admin') {
                            if(row.adminFlag == '0') {
                                return '<span class="label label-default">未审批</span>';
                            }else if(row.adminFlag == '1') {
                                return '<span class="label label-success">审批同意</span>';
                            }else {
                                return '<span class="label label-warning">审批不同意</span>';
                            }
                        } else if(verifyType == 'party') {
                            if(row.partyFlag == '0') {
                                return '<span class="label label-default">未审批</span>';
                            }else if(row.partyFlag == '1') {
                                return '<span class="label label-success">审批同意</span>';
                            }else {
                                return '<span class="label label-warning">审批不同意</span>';
                            }
                        }
                    }
                },
                {
                    field: 'deptName',
                    title: '所属科室'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'remark',
                    title: '备注'
                }]
            };
            $.table.init(options);
        });

        function verify(){
            var row = $("#bootstrap-table").bootstrapTable('getSelections')[0];
            var url = prefix + "/verify/" + row.leaveId + "/" + $("#verifyType").val();
            $.modal.openFull("请假审批", url);
        }
    </script>
</body>
</html>